package com.atguigu.demojuc.chap08;

import java.util.concurrent.*;

public class CustomizeThreadPoolDemo_ {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                2,
                5,
                0,
                TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new RejectedExecutionHandler() {
                    @Override
                    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                        executor.submit(r);
                    }
                }
        );
        for (int i = 1; i <= 20; i++) {
            String num = String.valueOf(i);
            Future<Integer> futureResult = threadPoolExecutor.submit(()->{
                        System.out.println((Thread.currentThread().getName() + "\t" + "----come in number = " + num));
                        return 100;
                    });
        }
    }

}
